package com.lili.order.service.impl.review;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lili.model.order.entity.PageMap;
import com.lili.model.order.entity.review.Review;
import com.lili.order.mapper.review.ReviewMapper;
import com.lili.order.service.review.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Map;

@Service
public class ReviewServiceImpl implements ReviewService {

    @Autowired
    ReviewMapper reviewMapper;
    @Override
    public int save(Review review) {
        return reviewMapper.insert(review);
    }

    @Override
    public int delete(Serializable id) {
        return reviewMapper.myDeleteById(id);
    }

    @Override
    public int update(Review review) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("id",review.getId());
        return reviewMapper.update(review,wrapper);
    }

    @Override
    public Page<Review> queryByPage(Map map) {
        PageMap pageMap=new PageMap(map);
        QueryWrapper wrapper=new QueryWrapper();
        if(map.containsKey("memberName")){
            wrapper.like("member_name",map.get("memberName"));
        }
        if(map.containsKey("goodsName")){
            wrapper.like("goods_name",map.get("goodsName"));
        }
        if(map.containsKey("reviewGrade")){
            wrapper.eq("review_grade",map.get("reviewGrade"));
        }
        if(map.containsKey("beginTime")&&map.containsKey("endTime")){
            wrapper.between("create_time",map.get("beginTime"),map.get("endTime"));
        }
        if(map.containsKey("storeId")){
            wrapper.eq("store_id",map.get("storeId"));
        }
           Page<Review> page=new Page<>(pageMap.getPage(),pageMap.getPageSize());
           reviewMapper.selectPage(page,wrapper);
        return  page;
    }
}
